#include "Irse.h"

Irse::Irse(Tree* Fvp, Distance* distance1)
{
	distance = distance1;
	Frst = new Forest();
	HeavyChild = Fvp->getHeavy();
	find_Irse(Fvp);
}

// a Preorder traversal
// only if Fvp is father of Fvp1
void Irse::find_Irse(Tree* Fvp, bool flag)
{
	static int currSize; 
	int i;
	if(flag)
	{
		currSize=Fvp->getData()->getDT();
	}
	Frst->AddLeftTree(Fvp);
	Fvp->getData()->setDC(currSize);
	currSize -= distance->DeleteNode(Fvp);
	if (Fvp == HeavyChild)
	{
		return;
	}
	for(i=Fvp->getChildrenCount()-1; i>=0 ; i--)
	{
		find_Irse(Fvp->getChild(i), false);
		if(Fvp->getChild(i)->getData()->getHeavy())
			break;
	}
}


Tree*  Irse::get_Fk(int k) 
{
	return Frst->getTree(k);
}
